<?php
include_once('common/header.php');
if($AppUI->id <= 0 || (isset($_SESSION['place']) && ($_SESSION['place'] <= 0))) {
	Vfriend_Function::redirect(HOST_BACKEND);
}
$arrParams 	= $objRequest->getParams();
$intAction 	= isset($arrParams['paction']) ? $arrParams['paction'] : 0;
$intDetail 	= isset($arrParams['de']) ? $arrParams['de'] : 0;
$intPlaceId = isset($arrParams['placeid']) ? $arrParams['placeid'] : null;
$arrPlaceId = isset($arrParams['pplaceid']) ? $arrParams['pplaceid'] : null;
$strBackUrl	= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : HOST_BACKEND;
$intError  	= 0;
if($intAction && (isset($arrPlaceId) || $intPlaceId)) {
	$objPlace	= new Place();
	switch ($intAction) {
		case 1: // active
		case 5: // suggest			
			if(isset($_SESSION['place']) && ($_SESSION['place']&1<<5) != 0) {	
				if($intDetail == 0) {
					foreach($arrPlaceId as $row) {
						$intUserId = $objRequest->getParam('puserid' . $row, 0);
						$intError  = $objPlace->updateStatus($AppUI->id,$row,1,32,$intUserId);
					}
				} else {
					$intUserId = $objRequest->getParam('uid', 0);
					$intError  = $objPlace->updateStatus($AppUI->id,$intPlaceId,1,32,$intUserId);
				}
			}
			else {
				$intError = 1;
			}
			break;
		case 2: // delete
			if(isset($_SESSION['place']) && ($_SESSION['place']&1<<3) != 0) {	
				if($intDetail == 0) {
					foreach($arrPlaceId as $row) {
						$intUserId = $objRequest->getParam('puserid' . $row, 0);
						$objPlace->updateStatus($AppUI->id,$row,4,8,$intUserId);
					}
				}else {
					$intUserId = $objRequest->getParam('uid', 0);
					$intError  = $objPlace->updateStatus($AppUI->id,$intPlaceId,4,8,$intUserId);
				}
			}
			else {
				$intError = 1;
			}
			break;
		case 3:
			if(isset($_SESSION['place']) && ($_SESSION['place']&1<<4) != 0) {	
				if($intDetail == 0) {
					foreach($arrPlaceId as $row) {
						$intUserId = $objRequest->getParam('puserid' . $row, 0);
						$objPlace->updateStatus($AppUI->id,$row,3,16,$intUserId);
					}
				}else {
					$intUserId = $objRequest->getParam('uid', 0);
					$intError  = $objPlace->updateStatus($AppUI->id,$intPlaceId,3,16,$intUserId);
				}
			}
			else {
				$intError = 1;
			}
			break;
		case 4: // delete database
			if(isset($_SESSION['place']) && ($_SESSION['place']&1<<3) != 0 && $AppUI->type > 1) {
				if($intDetail == 0) {
					foreach($arrPlaceId as $row) {
						$intUserId = $objRequest->getParam('puserid' . $row, 0);
						$objPlace->delete($AppUI->id,$row,$intUserId);
					}
				} else {
					$intUserId = $objRequest->getParam('uid', 0);
					$objPlace->delete($AppUI->id,$intPlaceId,$intUserId);
				}
			}
			else {
				$intError = 1;
			}
			break;	
		case 6: // accept img
			if(isset($_SESSION['place']) && ($_SESSION['place']&1<<4) != 0) {				
				$intUserId		= $objRequest->getParam('uid', 0);
				$intPimageId	= $objRequest->getParam('pimageid', 0);
				$intError		= $objPlace->updateStatusForImg($AppUI->id,$intPimageId,1,16,$intPlaceId,$intUserId);
				if($intError == 0) $intMessage = 5;
			}
			else {
				$intError = 1;
			}
			break;
		case 7: //delete img
			if(isset($_SESSION['place']) && ($_SESSION['place']&1<<3) != 0) {				
				$intUserId		= $objRequest->getParam('uid', 0);
				$intPimageId	= $objRequest->getParam('pimageid', 0);
				$objPlace->updateStatusForImg($AppUI->id,$intPimageId,3,8,$intPlaceId,$intUserId);
			}
			else {
				$intError = 1;
			}
			break;
		case 8: //delete database
			if(isset($_SESSION['place']) && ($_SESSION['place']&1<<3) != 0) {				
				$intUserId		= $objRequest->getParam('uid', 0);
				$intPimageId	= $objRequest->getParam('pimageid', 0);
				$objPlace->deleteImageForPlace($AppUI->id,$intPlaceId,$intPimageId);
			}
			else {
				$intError = 1;
			}
			break;
	}
} else {
	$intError = 1;
}
if($intError == 0) {
	Vfriend_Function::setMsg($arrMessage[$intAction]);
} else {
	Vfriend_Function::setError($arrError[$intError]);	
}
if($intDetail == 0) {
	Vfriend_Function::redirect($strBackUrl);
} else {
	$strRefer	= $objRequest->getParam('refer','');	
	Vfriend_Function::redirect(HOST_BACKEND . 'place/detail?placeid=' . $intPlaceId . '&refer=' . $strRefer);
}
?>